package edu.yctc.weblog.config;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import edu.yctc.weblog.constant.ConstantHolder;
import edu.yctc.weblog.constant.TemplatePath;
import edu.yctc.weblog.interceptor.AdminSignInInterceptor;

/**
 * 
 * @className WeblogWebMvcConfigurer
 * @description 系统配置类
 * @author zyj
 * @date 2020年6月16日
 *
 */
@Configuration
public class WeblogWebMvcConfigurer implements WebMvcConfigurer {

    @Autowired
    private AdminSignInInterceptor adminSignInInterceptor;

    public void addInterceptors(InterceptorRegistry registry) {
        // 添加一个拦截器，拦截以/admin为前缀的url路径
        registry.addInterceptor(adminSignInInterceptor)
            .addPathPatterns(TemplatePath.S + TemplatePath.ADMIN + TemplatePath.S + TemplatePath.W + TemplatePath.W)
            .excludePathPatterns(TemplatePath.S + TemplatePath.ADMIN + TemplatePath.S + TemplatePath.ADMIN_SIGN_IN)
            .excludePathPatterns(TemplatePath.S + TemplatePath.ADMIN + TemplatePath.S + TemplatePath.ADMIN_DIST
                + TemplatePath.S + TemplatePath.W + TemplatePath.W)
            .excludePathPatterns(TemplatePath.S + TemplatePath.ADMIN + TemplatePath.S + TemplatePath.ADMIN_PLUGINS
                + TemplatePath.S + TemplatePath.W + TemplatePath.W);
    }

    public void addResourceHandlers(ResourceHandlerRegistry registry) {
        registry.addResourceHandler("/upload/**").addResourceLocations("file:" + ConstantHolder.FILE_UPLOAD_DIC);
    }

}
